#include <iostream>
#include <fstream>
#include <map>
using namespace std;

/*
usage of the program:
sudo < input
sudo file1 file2 ... filen
if success solve result, it will print the result
if fail solve the result, it will print "unsolved case, print the number of the results"
*/

const int DIM = 9;
int board[DIM][DIM];
static void print_board();

static void clear_board() {
  for (int i = 0; i < DIM; ++i) {
    for (int j = 0; j < DIM; ++j) {
      board[i][j] = 0;
    }
  }
}

static void read_board(istream &in) {
  for (int i = 0; i < DIM; ++i) {
    for (int j = 0; j < DIM; ++j) {
      in>>board[i][j];
    }
  }
  cout<<"the board going to be solved:"<<endl;
  print_board();
}

static void print_board() {
  cout<<"Current status of the board:"<<endl;
  for (int i = 0; i < DIM; ++i) {
    for (int j = 0; j < DIM; ++j) {
      cout<<board[i][j]<<' ';
    }
    cout<<endl;
  }
}

/*
  check which number can be put in board[i][j]
  return number of the possibilities, 0 for error or no number
*/
int check_number(int i1, int j1, int & res) {
  //cout<<"pos: "<<i1<<' '<<j1<<endl;
  if (board[i1][j1]> 0 && board[i1][j1] <= DIM) return 0; // cube has already have a number
  map<int, int> mm;
  for (int i = 1; i <= DIM; ++i) mm[i] = 0;
  for (int i = 0; i < DIM; ++i) {
    //cout<<"checking: "<<i<<' '<<j1<<endl;
    if (board[i][j1]) mm[board[i][j1]] = 1;
  }
  for (int i = 0; i < DIM; ++i) {
    //cout<<"checking: "<<i1<<' '<<i<<endl;
    if (board[i1][i]) mm[board[i1][i]] = 1;
  }
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      //cout<<"checking: "<<i+(i1/3)*3<<' '<<j+(j1/3)*3<<endl;
      if (board[i+(i1/3)*3][j+(j1/3)*3]) {
        mm[board[i+(i1/3)*3][j+(j1/3)*3]] = 1;
      }
    }
  }
  int count = 0;
  for (int i = 1; i <= DIM; ++i) {
    if (mm[i] == 0) {
      count++;
      res = i;
    }
  }
  if (count > 1) res = 0;
  //cout<<i1<<' '<<j1<<' '<<res<<' '<<count<<endl;
  return count;
}

int solve_board(istream &in) {
  //clear_board();
  read_board(in);
  // do the rest to solve the board
  // Method 1: exclude the possibility of the blank and check
  int status = 1;
  while (status) {
    status = 0;
    for(int i = 0; i < DIM; ++i) {
      for (int j = 0; j < DIM; ++j) {
        if (board[i][j]) continue;
        // if this cube is unknown
        int res = 0;
        if (check_number(i, j, res) == 1) {
          board[i][j] = res;
          status = 1;
          //print_board();
        }
      }
    }
  }

  return 1; // unfinished work, return fail status
}

int main(int argc, char *argv[]) {
  //clear_board();
  if (argc == 1) {
    if (solve_board(cin)) {
      cout<<"unsolved case, may calculate the possibilities."<<endl;
    } else {
      print_board();
    }
    print_board();
  } else {
    for (int i = 1; i < argc; ++i) {
      ifstream fin(argv[i], ios::in);
      if(!fin) {
        cout<<"unable to open file: "<<argv[i]<<endl;
        continue;
      }
      if (solve_board(fin)) {
        cout<<"unsolved case, may calculate the possibilities."<<endl;
      } else {
        print_board();
      }
      print_board();
    }
  }
}
